package com.itheima.controller;

import com.itheima.pojo.CmsSubject;
import com.itheima.service.CmsSubjectService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/subject")
public class CmsSubjectController {

    @Autowired
    private CmsSubjectService cmsSubjectService;


    /**
     * 获取全部商品专题
     */
    @GetMapping("/listAll")
    public ResponseEntity listAll(){
        List<CmsSubject> cmsSubjectList = cmsSubjectService.listAll();
        return ResponseEntity.ok(Result.success(cmsSubjectList));
    }

    /**
     * 根据专题名称分页获取商品专题
     */
    @GetMapping("list")
    public ResponseEntity list(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String keyword){

        PageResultVo<CmsSubject> prv = cmsSubjectService.list(pageNum,pageSize,keyword);
        return ResponseEntity.ok(Result.success(prv));
    }


}
